package com.znzz.service.impl;

import com.znzz.dao.NewsDao;
import com.znzz.entity.News;
import com.znzz.service.NewsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(value = "newsService")
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsDao newsDao;

    @Override
    public int addNews(News news) {

        return newsDao.addNews(news);
    }

    @Override
    public boolean deleteNews(Integer newsId) {
        return newsDao.deleteNews(newsId);
    }

    @Override
    public boolean updateNews(News news) {
        return newsDao.updateNews(news);
    }


    @Override
    public List<News> queryNewsByCondition(Map<String, Object> map) {
        return newsDao.queryNewsByCondition(map);
    }

    @Override
    public List<News> findAllNews(Integer pageNum,  Integer pageSize) {
        if(pageNum==null || pageNum <=0){
            pageNum=1;
        }
        if(pageSize==null || pageSize <=0){
            pageSize=10;
        }

        Integer begin=(pageNum-1)*pageSize;
        return newsDao.findAllNews(begin,pageSize);
    }

    @Override
    public int countAllNews() {

        return newsDao.countAllNews();
    }

    @Override
    public News findById(Integer id) {
        return newsDao.findById(id);
    }


}
